<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>H+ 后台主题UI框架 - Bootstrap Table</title>
    <meta name="keywords" content="H+后台主题,后台bootstrap框架,会员中心主题,后台HTML,响应式后台">
    <meta name="description" content="H+是一个完全响应式，基于Bootstrap3最新版本开发的扁平化主题，她采用了主流的左右两栏式布局，使用了Html5+CSS3等现代技术">

    <link rel="shortcut icon" href="/admin/favicon.ico"> <link href="/admin/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="/admin/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="/admin/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="/admin/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link href="/admin/css/animate.css" rel="stylesheet">
    <link href="/admin/css/style.css?v=4.1.0" rel="stylesheet">
    <script src="/admin/js/jquery.min.js?v=2.1.4"></script>
    <style>
        a{
            color:#777;
        }
    </style>

</head>

<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="ibox-content">
            <div class="row">
                <form action="" method="post" class="form-horizontal m-t" enctype="multipart/form-data" id="signupForm" onsubmit="return false">
                    <input type="hidden" name="id" value="{{$piece->id}}">
                    <div class="form-group">
                        <label class="col-xs-3 control-label">图片：</label>
                        <div class="col-xs-10">
                            <input type="file" class="form-control" id='img' name='img'>
                            <img src="/upload/{{$piece->img}}" width="100" id="preview" alt="">
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-xs-8 col-sm-offset-3">
                            <button class="btn btn-primary" id="update" type="submit">提交</button>
                        </div>
                    </div>
                </form>
        </div>
    </div>

    <!-- 全局js -->
    <script src="/admin/js/jquery.min.js?v=2.1.4"></script>
    <script src="/admin/js/bootstrap.min.js?v=3.3.6"></script>
    <script src="/admin/js/layer.js"></script>

    <!-- 自定义js -->
    <script src="/admin/js/content.js?v=1.0.0"></script>


    <!-- Bootstrap table -->
    <script src="/admin/js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
    <script src="/admin/js/plugins/bootstrap-table/bootstrap-table-mobile.min.js"></script>
    <script src="/admin/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>

    <!-- jQuery Validation plugin javascript-->
    <!-- <script src='/admin/js/plugins/validate/jquery.validate.min.js'></script>
    <script src='/admin/js/plugins/validate/messages_zh.min.js'></script>

    <script src='/admin/js/demo/form-validate-demo.js'></script> -->
    <script src="/laydate/laydate.js"></script>

    <!-- Peity -->
    <!-- <script src="/admin/js/demo/bootstrap-table-demo.js"></script> -->
    <script src="/admin/js/plugins/iCheck/icheck.min.js"></script>
    <script src="/admin/js/plugins/peity/jquery.peity.min.js"></script>
    <script type="text/javascript" src="http://tajs.qq.com/stats?sId=9051096" charset="UTF-8"></script>
    <!--统计代码，可删除-->
    <script>
    </script>
    <script>
        // 更新
        $('#update').click(function(){
            var formdata=new FormData($('#signupForm')[0]);
            var index = parent.layer.getFrameIndex(window.name); //获取当前iframe层索引
            $.ajax({
                url:'/admin/goods/goodsimg_update',
                type:'POST',
                cache:false,
                data:formdata,
                processData: false,
                contentType: false,
                success:function(data){
                    // console.log(data);
                    if(data==1){
                        layer.msg('修改成功',{'icon':1});
                    }else{
                        layer.msg('修改失败',{'icon':2});
                    }
                    setTimeout(function(){
                        parent.layer.close(index); //关闭当前iframe层
                    },1000);
                }
            }).done(function(data){
                // console.log(data);
                window.parent.location.reload();
            }).fail(function(data){
                console.log(data);
                layer.msg('请正确填写信息',{'icon':2});
            })
        })
    </script>

    <!-- 预显示图片 -->
    <script>
        document.querySelector('#img').addEventListener('change', function(){
            //当没选中图片时，清除预览
            if(this.files.length === 0){
                document.querySelector('#preview').src = '';
                return;
            }
            
            //实例化一个FileReader
            var reader = new FileReader();

            reader.onload = function (e) {
                //当reader加载时，把图片的内容赋值给
                document.querySelector('#preview').src = e.target.result;
            };

            //读取选中的图片，并转换成dataURL格式
            reader.readAsDataURL(this.files[0]);
        }, false);
    </script>

</body>

</html>
